package main

import (
	"context"
	"dispatch-system/models"
	_ "dispatch-system/routers"
	"dispatch-system/service"

	"github.com/beego/beego/v2/client/orm"
	beego "github.com/beego/beego/v2/server/web"
	"github.com/beego/beego/v2/task"
)

func main() {
	// 初始化数据库
	models.Register()

	// 启动ORM
	orm.RunSyncdb("default", false, true)

	// 启动定时任务
	initTask()
	beego.Run()
}

// 初始化定时任务
func initTask() {
	// 定时任务
	tk1 := task.NewTask("OrderFinish", "0/10 * * * * *", func(ctx context.Context) error { service.OrderFinish(); return nil })
	task.AddTask("OrderFinish", tk1)
	tk2 := task.NewTask("OrderTimeoutCancel", "5/10 * * * * *", func(ctx context.Context) error { service.OrderTimeoutCancel(); return nil })
	task.AddTask("OrderTimeoutCancel", tk2)
	task.StartTask()
}
